package com.example.demo.tencent;

import com.alibaba.fastjson.JSON;
import com.example.demo.vo.BizLicenseOcrResult;
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;

import com.tencentcloudapi.ocr.v20181119.OcrClient;
import com.tencentcloudapi.ocr.v20181119.models.*;;

public class BizLicenseOCR
{
    public static void main(String [] args) {
        try{

            Credential cred = new Credential("AKIDbXE8pIu6ATXLs6NBzYLtpXGKTO2wkcqq", "Jyb09dXNyMVQ6XwI9m9HBpGUXNyIOGtG");

            HttpProfile httpProfile = new HttpProfile();
            httpProfile.setEndpoint("ocr.tencentcloudapi.com");

            ClientProfile clientProfile = new ClientProfile();
            clientProfile.setHttpProfile(httpProfile);

            OcrClient client = new OcrClient(cred, "ap-beijing", clientProfile);

            BizLicenseOCRRequest req = new BizLicenseOCRRequest();
            req.setImageUrl("https://cwc.clouderwork.com/clouderworkorg/e58533adc9204f5cbf7bdbe493b26ad9.jpg");

            BizLicenseOCRResponse resp = client.BizLicenseOCR(req);

            System.out.println(BizLicenseOCRResponse.toJsonString(resp));

            BizLicenseOcrResult bizLicenseOcrResult = new BizLicenseOcrResult();

            bizLicenseOcrResult.setAddress(resp.getAddress());
            bizLicenseOcrResult.setBusinessScope(resp.getBusiness());
            bizLicenseOcrResult.setCapital(resp.getCapital());
            bizLicenseOcrResult.setEntityName(resp.getName());
            bizLicenseOcrResult.setEntityType(resp.getType());
            bizLicenseOcrResult.setExpireDate(resp.getPeriod().substring(resp.getPeriod().indexOf("至")+1));
            bizLicenseOcrResult.setLegalPerson(resp.getPerson());
            bizLicenseOcrResult.setPeriod(resp.getPeriod());
            bizLicenseOcrResult.setRegNum(resp.getRegNum());
            bizLicenseOcrResult.setSetDate(resp.getSetDate());

            System.out.println(JSON.toJSONString(bizLicenseOcrResult));

        } catch (TencentCloudSDKException e) {
                System.out.println(e.toString());
        }

    }

}